package com.wingsboat.common.protect.keyconvert.impl;

import cn.hutool.crypto.SecureUtil;
import com.wingsboat.common.core.utils.uuid.IdUtils;
import com.wingsboat.common.protect.annotation.AthenaLock;
import com.wingsboat.common.protect.aspect.AthenaLockAspect;
import com.wingsboat.common.protect.keyconvert.KeyConvert;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author wangzhong
 * @description: 默认key转换器
 * @date 2024/5/30 16:19
 */
@Component
public class DefaultAthenaLockKeyConvert implements KeyConvert, InitializingBean {

    @Autowired
    private AthenaLockAspect athenaLockAspect;

    @Override
    public void afterPropertiesSet() throws Exception {
        athenaLockAspect.addKeyConvert(this);
    }

    /**
     * 获取key
     *
     * @param joinPoint
     * @param athenaLock
     * @return
     */
    @Override
    public String getKey(ProceedingJoinPoint joinPoint, AthenaLock athenaLock) {
        String methodName = joinPoint.getSignature().toString();
        String key = SecureUtil.md5(methodName);
        return key;
    }
}
